// components/toplist/index.js
import { request } from "../../utils/request.js";
import regeneratorRuntime, { values } from "../../utils/runtime.js";
var bsurl = require('../../utils/bsurl.js');
Component({
  properties: {
  },
  data: {
    topOne:[],
    topSecond:[],
    topThird:[],
    topFourth:[],
    topFifth:[],
    coverImgUrl:[],
    topFive:[],
    Topplaylist:[]
  },
  methods: {
    async getTopplaylist(){
      let playlistInfo=await request({url: bsurl+'toplist'});
      let Topplaylist=playlistInfo.list.splice(4).map(v=>{
        return{
          id:v.id,
          name:v.name,
          coverImgUrl:v.coverImgUrl
        }
      });
      let topFive=playlistInfo.list.splice(0,4).map(v=>v.id)
      this.setData({
        Topplaylist,
        topFive
      })
    },
    //前五的榜单
    async getTopFive(){
      //飙升榜单
      let playlitone=await request({url: bsurl+'top/list?idx=3'});
      let topOne=playlitone.playlist.tracks.splice(0,3).map(v=>{
        return{
          name:v.name,
          author:v.ar[0].name
        }
      });
      //新歌榜
      let playlitsecond=await request({url: bsurl+'top/list?idx=0'});
      let topSecond=playlitsecond.playlist.tracks.splice(0,3).map(v=>{
        return{
          name:v.name,
          author:v.ar[0].name
        }
      });
      //原创榜
      let playlitThird=await request({url: bsurl+'top/list?idx=2'});
      let topThird=playlitsecond.playlist.tracks.splice(0,3).map(v=>{
        return{
          name:v.name,
          author:v.ar[0].name
        }
      });
      //热歌榜
      let playlitFourth=await request({url: bsurl+'top/list?idx=1'});
      let topFourth=playlitsecond.playlist.tracks.splice(0,3).map(v=>{
        return{
          name:v.name,
          author:v.ar[0].name
        }
      });
      //歌手榜
      let playlitFifth=await request({url: bsurl+'toplist/artist'});
      let topFifth=playlitFifth.list.artists.splice(0,3).map(v=>{
        return{
          name:v.name,
          score:v.score
        }
      })
      //音乐封面
      let coverImgUrl=[playlitone.playlist.coverImgUrl,playlitsecond.playlist.coverImgUrl,playlitThird.playlist.coverImgUrl,
      playlitFourth.playlist.coverImgUrl]
      this.setData({
        topOne,
        topSecond,
        topThird,
        topFourth,
        topFifth,
        coverImgUrl
      })
    }
  },
  lifetimes: {
    created() {
      //console.log("在组件实例刚刚被创建时执行")
      this.getTopplaylist();
      this.getTopFive();
      console.log(this.data.coverImgUrl)
    },
  }
})
